package com.tiny.controller;

import com.jfinal.core.Controller;
import com.jfinal.kit.StrKit;
import com.jfinal.plugin.activerecord.Page;
import com.tiny.model.SysLog;

public class SysLogController extends Controller {
	
	public void index(){
		render("/frame/syslog.html");
	}
	
	public void  query(){
		StringBuilder sql = new StringBuilder(" from syslog where 1=1 ");

		if (StrKit.notBlank(this.getPara("starttime"))) {
			sql.append(String.format(" and starttime >= '%s' ",
					this.getPara("starttime")));
		}
		
		if (StrKit.notBlank(this.getPara("endtime"))) {
			sql.append(String.format(" and starttime <= '%s' ",
					this.getPara("endtime")));
		}
		
		if (StrKit.notBlank(this.getPara("sort"))) {
			sql.append(String.format("%s %s %s", "order by",this.getPara("sort"),this.getPara("order")));
		}
		else{
			sql.append(" order by id desc ");
		}

		Page<SysLog> page = SysLog.dao.paginate(this.getParaToInt("page"), this.getParaToInt("rows"),"select * ", sql.toString());
		
		setAttr("rows", page.getList());
		setAttr("total", page.getTotalRow());
		
		renderJson();
	}
}
